package util;

import model.Order;
import java.util.List;
import java.util.Random;

public class OrderCodeUtil { // 订单标识码生成工具类 完成人：姜凯严 7/1
    public static int generateUniqueOrderCode(List<Order> allOrders) {
        Random random = new Random();
        while (true) {
            int code = 10000000 + random.nextInt(90000000); // 8位
            boolean exists = false;
            for (Order o : allOrders) {
                if (o.getCode() == code) {
                    exists = true;
                    break;
                }
            }
            if (!exists) return code;
        }
    }
}
